// 定义分享数据
const shareData = {
  title: 'MDN',
  text: 'Learn web development on MDN!',
  url: 'https://developer.mozilla.org/en-US/docs/Web/API/Web_Share_API',
  files: [] // 一个 File 对象数组
};

const btn = document.querySelector("#share");
const resultPara = document.querySelector('.result');

// 通过用户交互后才能触发分享
btn.addEventListener('click', async () => {
  try {
    if (navigator.canShare(shareData)) {
      await navigator.share(shareData);
      resultPara.textContent = '分享成功';
    } else {
      resultPara.textContent = 'Error: 错误的数据结构';
    }
  } catch (err) {
    resultPara.textContent = 'Error: ' + err;
  }
})